module.exports = function request(options) {
    
    return new Promise((resolve, reject) => {
        wx.showLoading({
          title: 'loading',
        })
       
        let requestObj = {
            ...options,
            success(res) {
                resolve(res.data)
            },
            fail(err) {
                reject(err)
            },
            complete(res){
                wx.hideLoading()
                let {errcode,message} = res.data
                if(errcode === 40001){
                    wx.showToast({
                      title: '请重新登录',
                    })
                    wx.navigateTo({
                      url: '/pages/user/user',
                    })
                }
               
            }
        }

        // 获取token，携带到请求头authorization中
        let token = wx.getStorageSync('token')
        if(token){
            requestObj.header = {
                authorization:token
            }
        }
      
        wx.request(requestObj)
    })
}